/**     
 * @Title: DirectProducer.java   
 * @Package me.mq.exchange.producer   
 * @Description: TODO
 * @author weiwei 
 * @date 2018年5月30日 上午10:53:50   
 * @version V1.0     
 */
package me.mq.exchange.producer;

import me.mq.exchange.config.RabbitMQConfigWithDirectExchange;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.hutool.core.lang.Console;

/**
 * @ClassName: DirectProducer
 * @Description: TODO
 * @author weiwei
 * @date 2018年5月30日 上午10:53:50
 * 
 */
@Profile("direct")
@RestController
public class DirectProducer {

	@Autowired
	private RabbitTemplate rabbitTemplate;

	@GetMapping("/sendMessage")
	public Object sendMessage() {
		new Thread(() -> {
			int count = 2;
			for (int i = 0; i < count; i++) {
				String value = "apple " + i;
				Console.log("apple send message {}", value);
				rabbitTemplate.convertAndSend(RabbitMQConfigWithDirectExchange.EXCHANGE_NAME, RabbitMQConfigWithDirectExchange.ROUTING_KEY_APPLE, value);
			}
			for (int i = 0; i < count; i++) {
				String value = "banana " + i;
				Console.log("banana send message {}", value);
				rabbitTemplate.convertAndSend(RabbitMQConfigWithDirectExchange.EXCHANGE_NAME, RabbitMQConfigWithDirectExchange.ROUTING_KEY_BANANA, value);
			}
			for (int i = 0; i < count; i++) {
				String value = "orange " + i;
				Console.log("orange send message {}", value);
				rabbitTemplate.convertAndSend(RabbitMQConfigWithDirectExchange.EXCHANGE_NAME, RabbitMQConfigWithDirectExchange.ROUTING_KEY_ORANGE, value);
			}
		}).start();
		return "ok";
	}
}
